package com.mask.im.server.netty.action.handler;

import com.mask.im.server.netty.enums.IMActionEnum;
import com.mask.im.server.netty.model.IMReceiveMessage;
import io.netty.channel.Channel;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;

/**
 * @className： MaskIMVideoCallsHandler
 * @Description: 视频通话
 * @Author： jian
 * @Date： 2025/8/29 11:23
 */
@Log4j2
@Component
public class IMVideoCallsHandler extends IMAbstractChatHandler {

    @Override
    public IMActionEnum getAction() {
        return IMActionEnum.VIDEO_CALLS;
    }

    @Override
    public void handle(IMReceiveMessage imReceiveMessage, Channel channel) {
//        Integer type = imReceiveMessage.getExtend();
//        String receiverId = imReceiveMessage.getReceiverId().toString();
//        switch (type) {
//            case 1:
//                request(channel, receiverId);
//                break;
//            case 2:
//                response(receiverId);
//                break;
//            case 3:
//                askOffer(receiverId);
//                break;
//            case 4:
//                getOffer(imReceiveMessage.getContent(), receiverId);
//                break;
//            case 5:
//                answer(imReceiveMessage.getContent(), receiverId);
//                break;
//            case 6:
//                candidate(imReceiveMessage.getContent(), receiverId);
//                break;
//            case 7:
//                hangUp(receiverId, channel);
//                break;
//            case 8:
//                closeVideo(receiverId, channel);
//        }
    }

//    private void closeVideo(String receiverId, Channel channel) {
//        Channel userIdChannel = channelService.getUserIdChannel(receiverId);
//        IMSendMessage websocketDTO = new IMSendMessage();
//        websocketDTO.setCmd(30007);
//        websocketDTO.setMessage(8);
//        if (userIdChannel != null) {
//            websocketDTO.setData("对方已挂断视频通话");
//            userIdChannel.writeAndFlush(new TextWebSocketFrame(JSON.toJSONString(websocketDTO)));
//        }
//        websocketDTO.setData("视频通话结束");
//        channel.writeAndFlush(new TextWebSocketFrame(JSON.toJSONString(websocketDTO)));
//    }
//
//    private void hangUp(String receiverId, Channel channel) {
//        Channel userIdChannel = channelService.getUserIdChannel(receiverId);
//        IMSendMessage websocketDTO = new IMSendMessage();
//        websocketDTO.setCmd(30007);
//        websocketDTO.setMessage(7);
//        if (userIdChannel != null) {
//            websocketDTO.setData("对方已挂断视频通话");
//            userIdChannel.writeAndFlush(new TextWebSocketFrame(JSON.toJSONString(websocketDTO)));
//        }
//        websocketDTO.setData("已挂断");
//        channel.writeAndFlush(new TextWebSocketFrame(JSON.toJSONString(websocketDTO)));
//    }
//
//    private void candidate(Object content, String receiverId) {
//        Channel userIdChannel = channelService.getUserIdChannel(receiverId);
//        IMSendMessage websocketDTO = new IMSendMessage();
//        websocketDTO.setCmd(30007);
//        websocketDTO.setMessage(6);
//        websocketDTO.setData(content);
//        userIdChannel.writeAndFlush(new TextWebSocketFrame(JSON.toJSONString(websocketDTO)));
//    }
//
//    private void answer(Object content, String receiverId) {
//        Channel userIdChannel = channelService.getUserIdChannel(receiverId);
//        IMSendMessage websocketDTO = new IMSendMessage();
//        websocketDTO.setCmd(30007);
//        websocketDTO.setMessage(5);
//        websocketDTO.setData(content);
//        userIdChannel.writeAndFlush(new TextWebSocketFrame(JSON.toJSONString(websocketDTO)));
//    }
//
//    private void getOffer(Object offer, String receiverId) {
//        Channel userIdChannel = channelService.getUserIdChannel(receiverId);
//        IMSendMessage websocketDTO = new IMSendMessage();
//        websocketDTO.setCmd(30007);
//        websocketDTO.setMessage(4);
//        websocketDTO.setData(offer);
//        userIdChannel.writeAndFlush(new TextWebSocketFrame(JSON.toJSONString(websocketDTO)));
//    }
//
//    private void askOffer(String receiverId) {
//        Channel userIdChannel = channelService.getUserIdChannel(receiverId);
//        IMSendMessage websocketDTO = new IMSendMessage();
//        websocketDTO.setCmd(30007);
//        websocketDTO.setMessage(3);
//        userIdChannel.writeAndFlush(new TextWebSocketFrame(JSON.toJSONString(websocketDTO)));
//    }
//
//    private void response(String receiverId) {
//        Channel userIdChannel = channelService.getUserIdChannel(receiverId);
//        IMSendMessage websocketDTO = new IMSendMessage();
//        websocketDTO.setCmd(30007);
//        websocketDTO.setMessage(2);
//        HashMap<String, String> hashMap = new HashMap<>();
//        hashMap.put("from", MaskSecurityUtil.getCurrentUserId().toString());
//        websocketDTO.setData(hashMap);
//        userIdChannel.writeAndFlush(new TextWebSocketFrame(JSON.toJSONString(websocketDTO)));
//    }
//
//    private void request(Channel channel, String receiverId) {
//        IMSendMessage websocketDTO = new IMSendMessage();
//        websocketDTO.setCmd(30007);
//        Channel userIdChannel = channelService.getUserIdChannel(receiverId);
//        Long requesterId = MaskSecurityUtil.getCurrentUserId();
//        if (userIdChannel != null) {
//            websocketDTO.setMessage(1);
////            UserInfo userInfo = userInfoService.getOne(new LambdaQueryWrapper<UserInfo>()
////                    .select(UserInfo::getId, UserInfo::getAvatar, UserInfo::getNickName)
////                    .eq(UserInfo::getId, requesterId));
//            UserInfo userInfo = new UserInfo();
//            websocketDTO.setData(userInfo);
//            userIdChannel.writeAndFlush(new TextWebSocketFrame(JSON.toJSONString(websocketDTO)));
//        } else {
//            websocketDTO.setMessage(-1);
//            channel.writeAndFlush(new TextWebSocketFrame(JSON.toJSONString(websocketDTO)));
//        }
//    }
}
